Add a Kind argument to target_filenames
authorAlex Crichton <alex@alexcrichton.com>
Thu, 7 May 2015 02:29:05 +0000 (19:29 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 7 May 2015 02:29:05 +0000 (19:29 -0700)
Knowing the target architecture for calculating the filename is needed when
calculating the name of a dynamic library, and previously this was only taken
into account when a target was a plugin. Targets can, however, request that they
are built as a dynamic library which also needs to be taken into account.

Closes #1589

src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs

index 585426cf37b988fecfef5a464a020bd7ca46aa32..cbeb3e61b7ab62eaa15499f237768ce2f1796c75 100644 (file)
@@ -7,7 +7,7 @@ use core::{PackageSet, Profiles, Profile};
 use core::source::{Source, SourceMap};
 use sources::PathSource;
 use util::{CargoResult, human, ChainError, Config};
-use ops::{self, Layout, Context, BuildConfig};
+use ops::{self, Layout, Context, BuildConfig, Kind};
 
 pub struct CleanOptions<'a, 'b: 'a> {
     pub spec: Option<&'a str>,
@@ -63,7 +63,8 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {
         try!(rm_rf(&layout.fingerprint(&pkg)));
         let profiles = [Profile::default_dev(), Profile::default_test()];
         for profile in profiles.iter() {
-            for filename in try!(cx.target_filenames(&pkg, target, profile)).iter() {
+            for filename in try!(cx.target_filenames(&pkg, target, profile,
+                                                     Kind::Target)).iter() {
                 try!(rm_rf(&layout.dest().join(&filename)));
                 try!(rm_rf(&layout.deps().join(&filename)));
             }
index 9cfa05a17e415f5a7d5101cbf9237bc4950ad649..cb52e9446f5885f798d5b183644c6ae4e067d69d 100644 (file)
@@ -299,7 +299,8 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
     /// Return the filenames that the given target for the given profile will
     /// generate.
     pub fn target_filenames(&self, pkg: &Package, target: &Target,
-                            profile: &Profile) -> CargoResult<Vec<String>> {
+                            profile: &Profile, kind: Kind)
+                            -> CargoResult<Vec<String>> {
         let stem = self.file_stem(pkg, target, profile);
         let suffix = if target.for_host() {&self.host_exe} else {&self.target_exe};
 
@@ -316,8 +317,6 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
                 for lib in libs.iter() {
                     match *lib {
                         LibKind::Dylib => {
-                            let plugin = target.for_host();
-                            let kind = if plugin {Kind::Host} else {Kind::Target};
                             let (prefix, suffix) = try!(self.dylib(kind));
                             ret.push(format!("{}{}{}", prefix, stem, suffix));
                         }
index 707f0ccb9003e732a43beb11de3b39bd52e65758..0b1ac8aa1201ab9ad00bf0f479763813a18ff239 100644 (file)
@@ -51,13 +51,14 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
 
     info!("fingerprint at: {}", loc.display());
 
-    let fingerprint = try!(calculate(cx, pkg, target, profile, kind));
-    let is_fresh = try!(is_fresh(&loc, &fingerprint));
+    let mut fingerprint = try!(calculate(cx, pkg, target, profile, kind));
+    let is_fresh = try!(is_fresh(&loc, &mut fingerprint));
 
     let root = cx.out_dir(pkg, kind, target);
     let mut missing_outputs = false;
     if !profile.doc {
-        for filename in try!(cx.target_filenames(pkg, target, profile)).iter() {
+        for filename in try!(cx.target_filenames(pkg, target, profile,
+                                                 kind)).iter() {
             missing_outputs |= fs::metadata(root.join(filename)).is_err();
         }
     }
index e1535bb8f3e0d72b4276b16388c910530da148f2..21177e965b5cf138d4d326b35e4d71d488e0410c 100644 (file)
@@ -133,8 +133,10 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
     cx.compilation.extra_env.insert("OUT_DIR".to_string(), out_dir);
 
     for &(target, profile) in targets {
-        for filename in try!(cx.target_filenames(pkg, target, profile)).iter() {
-            let dst = cx.out_dir(pkg, Kind::Target, target).join(filename);
+        let kind = Kind::Target;
+        for filename in try!(cx.target_filenames(pkg, target, profile,
+                                                 kind)).iter() {
+            let dst = cx.out_dir(pkg, kind, target).join(filename);
             if profile.test {
                 cx.compilation.tests.push((target.name().to_string(), dst));
             } else if target.is_bin() || target.is_example() {
@@ -154,10 +156,9 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)],
                 if profile.doc { continue }
                 if cx.compilation.libraries.contains_key(&pkgid) { continue }
 
-                let v = try!(cx.target_filenames(pkg, target, profile));
+                let v = try!(cx.target_filenames(pkg, target, profile, kind));
                 let v = v.into_iter().map(|f| {
-                    (target.clone(),
-                     cx.out_dir(pkg, Kind::Target, target).join(f))
+                    (target.clone(), cx.out_dir(pkg, kind, target).join(f))
                 }).collect::<Vec<_>>();
                 cx.compilation.libraries.insert(pkgid.clone(), v);
             }
@@ -342,7 +343,8 @@ fn rustc(package: &Package, target: &Target, profile: &Profile,
         }
         let exec_engine = cx.exec_engine.clone();
 
-        let filenames = try!(cx.target_filenames(package, target, profile));
+        let filenames = try!(cx.target_filenames(package, target, profile,
+                                                 kind));
         let root = cx.out_dir(package, kind, target);
 
         // Prepare the native lib state (extra -L and -l flags)
@@ -753,13 +755,14 @@ fn build_deps_args(cmd: &mut CommandPrototype,
         // If this target is itself a plugin *or* if it's being linked to a
         // plugin, then we want the plugin directory. Otherwise we want the
         // target directory (hence the || here).
-        let layout = cx.layout(pkg, match kind {
+        let kind = match kind {
             Kind::Host => Kind::Host,
             Kind::Target if target.for_host() => Kind::Host,
             Kind::Target => Kind::Target,
-        });
+        };
+        let layout = cx.layout(pkg, kind);
 
-        for filename in try!(cx.target_filenames(pkg, target, profile)).iter() {
+        for filename in try!(cx.target_filenames(pkg, target, profile, kind)).iter() {
             if filename.ends_with(".a") { continue }
             let mut v = OsString::new();
             v.push(&target.crate_name());